package service

import (
	"guliedu/model"
	"guliedu/repository"
	"mime/multipart"
)

type IEduCourseService interface {
	Insert(c *model.EduCourse) error
	UploadCover(file multipart.File, fileSize int64) (string, int)
	Select(id string) (*model.EduCourse, error)
	Update(course *model.EduCourse) error
	SelectAllCourse() ([]model.EduCourse, error)
	Delete(id string) error
	SelectIndexHotCourse() ([]model.EduCourse, error)
	SelectCourseByTeacherID(id string) ([]model.EduCourse, error)
	SelectFrontCourse(page, pageSize, subjectParentID, subjectID int) ([]model.EduCourse, error)
	SelectCourseCount() (int64, error)
	CacheCourses([]model.EduCourse) error
	GetCacheCourse() []model.EduCourse
}

func NewIEduCourseService() IEduCourseService {
	return &EduCourseService{EduCourseRepository: repository.NewIEduCourseRepository()}
}

type EduCourseService struct {
	EduCourseRepository repository.IEduCourseRepository
}

func (t *EduCourseService) Insert(c *model.EduCourse) error {
	return t.EduCourseRepository.Insert(c)
}

func (t *EduCourseService) UploadCover(file multipart.File, fileSize int64) (string, int) {
	return t.EduCourseRepository.UploadCover(file, fileSize)
}

func (t *EduCourseService) Select(id string) (*model.EduCourse, error) {
	return t.EduCourseRepository.Select(id)
}

func (t *EduCourseService) Update(course *model.EduCourse) error {
	return t.EduCourseRepository.Update(course)
}

func (t *EduCourseService) SelectAllCourse() ([]model.EduCourse, error) {
	return t.EduCourseRepository.SelectAllCourse()
}

func (t *EduCourseService) Delete(id string) error {
	return t.EduCourseRepository.Delete(id)
}

func (t *EduCourseService) SelectIndexHotCourse() ([]model.EduCourse, error) {
	return t.EduCourseRepository.SelectIndexHotCourse()
}

func (t *EduCourseService) SelectCourseByTeacherID(id string) ([]model.EduCourse, error) {
	return t.EduCourseRepository.SelectCourseByTeacherID(id)
}

func (t *EduCourseService) SelectFrontCourse(page, pageSize, subjectParentID, subjectID int) ([]model.EduCourse, error) {
	return t.EduCourseRepository.SelectFrontCourse(page, pageSize, subjectParentID, subjectID)
}

func (t *EduCourseService) SelectCourseCount() (int64, error) {
	return t.EduCourseRepository.SelectCourseCount()
}

func (t *EduCourseService) CacheCourses(courses []model.EduCourse) error {
	return t.EduCourseRepository.CacheCourses(courses)
}

func (t *EduCourseService) GetCacheCourse() []model.EduCourse {
	return t.EduCourseRepository.GetCacheCourse()
}
